package com.snopy.reference.strong;

import java.util.concurrent.TimeUnit;

/**
 * @author snopy
 * @version 1.0.0
 * @classname StrongReferenceDemo
 * @description
 * @email 77912204@qq.com
 * @date 2022/03/15 20:11
 */
public class StrongReferenceDemo {
    public static void main(String[] args) throws InterruptedException {
        Object m1 = new ClassMemory();
        Object m2 = new ClassMemory();
        Object m3 = new ClassMemory();
        Object m4 = new ClassMemory();
        System.out.println(m1);
        System.out.println(m2);
        m1 = null;
        m2 = null;
        System.gc();
        TimeUnit.SECONDS.sleep(3);
        System.out.println(m3);

        System.out.println(m4);
    }
}

/**
 * 模拟1M内存
 */
class ClassMemory{
     private final byte[] memory = new byte[1048576];
}
